package com.dongnao.jack.loadbalance;

import java.util.List;

import com.dongnao.jack.service.store.ParseServiceFactory;

public class PollBalance implements Balance {

    private String flag = "poll";

    private int index = 0;

    @Override
    public NodeRegisterInfo getRegisterInfo(List<String> registerList, String type) {

        if (index >= registerList.size()) {
            index = 0;
        }

        String registerInfo = registerList.get(index);

        NodeRegisterInfo register = new NodeRegisterInfo();

        register.setRegisterInfo(registerInfo);
        register.setType(type);
        register.setHost(ParseServiceFactory.getParseService(type).parseHost(registerInfo));
        register.setPort(ParseServiceFactory.getParseService(type).parsePort(registerInfo));
        return register;
    }

    @Override
    public boolean support(String anFlag) {

        return flag.equals(anFlag);
    }

}
